package com.reactor.handler.commands;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.w3c.dom.Element;

import utils.XmlUtils;

import com.reactor.handler.ICommand;
import com.reactor.handler.ICommandResult;

public class SearchProductCommand implements ICommand{
	public static final String SEARCH_PRODUCT_COMMAND = "SearchProduct";
	
	private static final String SEARCH_PRODUCT_START_WITH = "productNameStarts";
	
	private String productNameStarts;
	public SearchProductCommand(Element body)
	{
		this.parse(body);
	}
	@Override
	public ICommandResult execute() {
		System.out.println("EXECUTED!!!!!!" + productNameStarts);
		String result="BAD RESULT";
		File xmlFile = new File("command.xml");
		try {
			result = FileUtils.readFileToString(xmlFile, "UTF-8");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return new SearchCommandResult(result);
		
	}
	@Override
	public void parse(Element commandsBody) {
		this.productNameStarts = XmlUtils.getTextValue(commandsBody,SearchProductCommand.SEARCH_PRODUCT_START_WITH);
		
	}

}
